package org.asg.dis.service;

import org.asg.dis.model.Shipment;
import org.asg.dis.model.ShipmentStatus;
import org.asg.dis.model.Trace;
import org.asg.dis.repository.TraceRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class TraceService {

    @Autowired
    private TraceRepository traceRepository;

    public Trace createTrace(Shipment shipment, ShipmentStatus status, String location, String note) {
        Trace trace = new Trace(shipment, status, location, LocalDateTime.now(), note);
        return traceRepository.save(trace);  // 保存到数据库
    }

    public List<Trace> getTrackingInfo(Shipment shipment) {
        return traceRepository.findByShipmentIdOrderByTimestampAsc(shipment);  // 根据货件ID获取所有运输历史记录
    }
}
